#include "locus.h"

Locus::Locus( QString geno ) {
    setGenotype( geno );
}

bool Locus::isHeterozygote() {
    if( ploidy() < 2 )
        return false;

    else if( ploidy() == 2 )
        return (_alleles[0] != _alleles[1] );

    else {
        QString allele = _alleles[0];
        for(int i=1;i<_alleles.count();i++){
            if( _alleles[i] != allele )
                return true;
        }
        return false;
    }
}

QString Locus::getAllele(int idx){
    if( idx < ploidy() )
        return _alleles[idx];
    else
        return QString("");
}

void Locus::addAllele(QString val ){
    _alleles.append(val);
    _alleles.sort();
}

void Locus::setAllele(int idx, QString val){
    if( idx < ploidy() )
        _alleles[idx] = val;
}

void Locus::setGenotype(QString val) {
    _alleles = val.split(":",QString::SkipEmptyParts);
}

bool Locus::operator==(const Locus &other ) const {
    return (other._alleles == _alleles);
}
